package selef.xiafan.config;

import org.springframework.boot.SpringBootConfiguration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/*
 * 配置生效拦截器
 * */

@SpringBootConfiguration
public class MyWebConfigurer implements WebMvcConfigurer {

//    @Bean
//    public LoginIntercepter getLoginIntercepter() {
//        return new LoginIntercepter();
//    }

//    @Override
//    public void addInterceptors(InterceptorRegistry registry) {
//        registry.addInterceptor(getLoginIntercepter())
//                .addPathPatterns("/**")
//                .excludePathPatterns("/index.html")
//                .excludePathPatterns("/api/logout")
//                .excludePathPatterns("/api/login")
//                .excludePathPatterns("/api/register");
//    }

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowCredentials(true) // 允许跨域使用cookie情况
                .allowedOrigins("http://localhost:8082")
                .allowedMethods("GET","POST","PUT","OPTIONS","DELETE")
                .allowedHeaders("*");

    }
}

